dealing_pos = Ext.extend(Ext.Panel,{
	id:'dealing_pos',  
	title:'POS页面',  
	closable:true,
	layout:'fit', //如果用函数来创建该面板的话,布局必须设置为fit,否则不会显示该面板中的内容	
	width:600,
    createPanel:function() {
//主设计开始
	//中间变量
		//控制及数据初始化
		function inputEnableCtr(){
			var isMemberCheck = Ext.getCmp('pos-form-member-check');
			var consumerField = Ext.getCmp('pos-form-consumer-field');
			posMemberMessageStore.removeAll() ;//清空用户信息,出售和出租不用清空
			consumerField.setValue('');
			//...清空归还部分暂时没做
			
			if (isMemberCheck.getValue()){
				consumerField.disable();
				Ext.getCmp('pos-form-tabpanel').getActiveTab().getComponent(0).getComponent(0).focus(true);
			}else{
				consumerField.enable();
				consumerField.focus(true);
			}
		}
		//用于出售小计 数据
		 posMaskTotalData = {
				goods_num	:0			,//出售商品数量，由总额更新函数得到
				sum			:0			,//出售商品总金额，同上
				point		:0			,//出售商品可积分，同上
				point_		:0			,//享用优惠需积分，同上
				gifts		:Array()	,//出售商品可得的礼品，同上

				_cash		:0			,//从上面出售总额计算得到的 返现 优惠，由优惠处理函数得到
				_discount	:1			,//             ..          折扣，同上
				_point		:0			,//             ..          需积分，同上
				_gifts		:Array()	,//             ..          礼品，同上
				
				set			:function(name,value){
					switch (name) {
					   case "goods_num" :
						   this.goods_num =value; 
						   break;
					   case "sum" :
						   this.sum =value;
						   break;
					   case "point" :
						   this.point =value;
						   break;
					   case "gifts" :
						   this.gifts =value;
						   break;
					   case "_cash" :
						   this._cash =value; 
						   break;
					   case "_discount" :
						   this._discount =value;
						   break;
					   case "_point" :
						   this._point =value;
						   break;
					   case "_gifts" :
						   this._gifts =value;
						   break;
					   default :
						   return;
					} 
				},
				get		:function(name){
					switch (name) {
					   case "goods_num" :
						   return this.goods_num;
					   case "sum" :
						   return this.sum;
					   case "point" :
						   return this.point;
					   case "gifts" :
						   return this.gifts;
					   case "_cash" :
						   return this._cash;
					   case "_discount" :
						   return this._discount;
					   case "_point" :
						   return this._point;
					   case "_gifts" :
						   return this._gifts;
					   default :
						   return;
					} 
				}
			}
		//用于总额显示的模板
		var posMaskTotalTpl = new Ext.XTemplate(
				'<div class="posSubTotalViewPanel"><table width="500"  >',
				  '<tr> ',
					'<td colspan="2">小计:</td>',
					'<td colspan="2">优惠:</td>',
					'<td>礼品:</td>',
				  '</tr>',
				  '<tr> ',
					'<td width="36" align="center">数量</td>',
					'<td width="64"> {goods_num}</td>',
					'<td width="54" align="center">返现</td>',
					'<td width="64"> ￥{[values._cash.toFixed(2)]}</td>',
					'<td rowspan="3" valign="top"> ',
					  '<div class="PanelScroll" > ',
						'<table class="posGiftView" width="100%" >',
							'<tr><th width="18">id</th><th>名称</th><th width="36">数量</th></tr>',
							'<tpl if="gifts != null">',
								'<tpl for="gifts">',
									'<tr><td>{[values.gift_id]}</td><td>{[values.gift_name]}</td><td>{[values.gift_num]}</td></tr>',
								'</tpl>',
							'</tpl>',
							'<tpl if="_gifts != null">',
								'<tpl for="_gifts">',
									'<tr><td>{[values.gift_id]}</td><td>{[values.gift_name]}</td><td>{[values.gift_num]}</td></tr>',
								'</tpl>',
							'</tpl>',
							'<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>',
						'</table>',
					  '</div></td>',
				  '</tr>',
				  '<tr> ',
					'<td align="center">金额</td>',
					'<td> ￥{[values.sum.toFixed(2)]}</td>',
					'<td align="center">折扣</td>',
					'<td> {_discount}</td>',
				  '</tr>',
				  '<tr> ',
					'<td align="center">积分</td>',
					'<td> {[values.point.toFixed(2)]}</td>',
					'<td align="center">需积分</td>',
					'<td>{_point}</td>',
				  '</tr>',
				'</table><div ><FONT SIZE="3px" COLOR="red">出售小计: ￥{[(values.sum*values._discount-values._cash).toFixed(2)]}</FONT></div></div>'
				
			);
		function posShowMaskTotal(){
			posMaskTotalTpl.overwrite('pos-mark-total-view',posMaskTotalData);
		}
		//用于优惠列表的数据
		var posPreferentialRecordType = Ext.data.Record.create([
			//下面是优惠的属性
			{name:'preferential_id'	,mapping:'preferential_id'	},//优惠ID号
			{name:'name'			,mapping:'name'				},//优惠名称
			{name:'memo'			,mapping:'memo'				},//优惠说明
			{name:'start'			,mapping:'start'			},//优惠开始时间
			{name:'end'				,mapping:'end'				},//优惠结束时间
			{name:'consumer_id'		,mapping:'consumer_id'		},//客户id
			{name:'level'			,mapping:'level'			},//适用会员等级
			{name:'owner_level'		,mapping:'owner_level'		},//最低用户等级
			//下面是优惠互斥数组
			{name:'excludes'		,mapping:'excludes'			},//其变量类型为js数组
			//下面是优惠的计算条件
			{name:'loop'			,mapping:'loop'				},//是否循环
			{name:'tradetype_id'	,mapping:'tradetype_id'		},//适用的交易方式
			{name:'goods_id'		,mapping:'goods_id'			},//适用的商品
			{name:'sum'				,mapping:'sum'				},//适用的金额
			{name:'goods_num'		,mapping:'goods_num'		},//适用的数量
			{name:'point'			,mapping:'point'			},//适用的积分
			//下面是优惠的结果
			{name:'subPoint'		,mapping:'point'			},//point域也用于要扣除的积分数值
			{name:'gifts'			,convert:function(v,rec){
												if(null == rec.gift_id) return null;
												return Array({	"gift_id":rec.gift_id,//增送礼品
																"gift_name":rec.gift_name,//增送礼品名称
																"gift_num":rec.gift_num ,//    其数量
																"gift_totalnum":rec.gift_totalnum//增送礼品库存
														});
											}},
			{name:'cash'			,mapping:'cash'				},//返还的现金
			{name:'discount'		,mapping:'discount'			} //给客户的折扣
		]);
		
		var posPreferentialReader = new Ext.data.JsonReader({root:"Preferential"},posPreferentialRecordType);

		posPreferentialStore = new Ext.data.Store({
			reader:posPreferentialReader,
			listeners:{
				'remove':	function( thisStore,thisRecord,idx ){//如果优惠列表数据中有被删除
								//更新优惠列表的显示
								posPreferentialMessageDataView.refresh() ;posPreferRefush();
							}
				//,'remove':	posPreferRefush
				,'add'	:	function(){posPreferRefush() ;}
				,scope	:this
				,delay:25
				}
			});

		//下面的代码用于显示出优惠列表的信息
		var posPreferentialMessageTpl = new Ext.XTemplate( //显示优惠列表的模板for=posPreferCheck_{preferential_id}
				'<tpl for=".">',
				'<div class="posPreferDetial" id ="posPreferDetialDiv_{preferential_id}" >',
					'<input type="checkbox"  id="posPreferCheck_{preferential_id}" value={preferential_id}/>',
					'<label > {name}</label>',
				'</div>',
				'</br>',
				'</tpl>'
		);
		//显示优惠列表的 DataView
		var posPreferentialMessageDataView = new Ext.DataView({ 
			store: posPreferentialStore,
			tpl: posPreferentialMessageTpl,
			autoHeight:true,			
			autoLoad:true,
			multiSelect: false,
			//overClass:'x-view-over',
			itemSelector:'div.posPreferDetial',
			emptyText: '<div class="posPreferentialMessage">没有优惠信息！</div>',
			listeners:	{click:function(thisDataView,index,node,e){if(e.target.tagName == 'INPUT'){
										posPreferExOpt(node.id.substring(19,node.id.length));//优惠列表中的列被点击 执行优惠互斥的自动选择功能
										posMarkAllGoodPre();//更新商品列表中的每个商品的优惠项,并更新小计数据
										
								}}
						}
		});
		//下面的代码用于选择优惠列表时更新互斥
		
			//更新列表中每个优惠的互斥关系 
		function posPreferRefush(){
			function goRefush(r){
				var p_id = r.get('preferential_id');
				posPreferExOpt(p_id)
			}
			posPreferentialStore.each(goRefush);
			posMarkAllGoodPre();
		}
			//优惠互斥的自动选择功能，只要输入一个优惠列表中存在的优惠ID，就会使它 于其互斥的 存在的优惠 的选择状态 被取相反状态
		function posPreferExOpt(preId){
			var Exs = posPreferentialStore.getAt(posPreferentialStore.find('preferential_id',preId)).get('excludes');
			if (Exs == null ) return;
			for (var i=0;i<Exs.length ;i++ ){
				 if (-1 != posPreferentialStore.find('preferential_id',Exs[i])) 
					Ext.getDom('posPreferCheck_'+Exs[i]).checked = !Ext.getDom('posPreferCheck_'+preId).checked;
			}
		}

		//更新数据中的优惠信息函数(私有)
		function posUpdataDataRecord(thisdata,_cash,_discount,_gifts,init){
			if (_cash ==null) _cash = 0;
			if (_discount ==null) _discount = 1;

			if(init){
				thisdata.set('_cash',_cash);
				thisdata.set('_discount',_discount);
				thisdata.set('_gifts',_gifts);
			}else{
				thisdata.set('_cash',thisdata.get('_cash')*1+_cash*1);
				thisdata.set('_discount',thisdata.get('_discount')*_discount);
				var g1 = thisdata.get('_gifts');
				var g0 = Array();
				if (_gifts!=null){
					if(g1!=null){
						
						thisdata.set('_gifts',g1.concat(_gifts));
					}else{
						thisdata.set('_gifts',_gifts);
					}
				}

			}
		}
		//更新商品列表中的每个商品的优惠项,并更新小计数据
		function posMarkAllGoodPre(Tx){
			if(Tx == null) Tx = 1;
			var P0 =Array();
			var P1 =Array();
			var P2 =Array();
			//把优惠列表中的所有列分解成p0 p1 p2
			function analyse(r){
				var t = r.get('tradetype_id');
				var g = r.get('goods_id');
				var c = r.get('consumer_id');
				var l = r.get('level');
				var o = r.get('owner_level');
				if( t!=null && t!=Tx && ( Ext.getDom('posPreferCheck_'+r.get('preferential_id')).checked ==false ) ) return;
				if( g ==null ) {P0.push(r)};
				if( g!=null && (c!=null || l!=null || o!=null)) {P1.push(r)};
				if( g!=null && (c==null && l==null && o==null)) {P2.push(r)};
			}
			posPreferentialStore.each(analyse);
			function all(dataRecord){
				 posMarkOneGoodPreCal(dataRecord,P0,P1,P2,1);
			}
			markStore.each(all);//更新每一个商品优惠数据
			posMarkSubtotalCal(posMaskTotalData,P0,Tx);//更新小计数据优惠
		}
		//计算出售小计的优惠函数,并更新小计显示
		function posMarkSubtotalCal(dataRecord,P0,Tx){
			//计算小计中的金额和总数 积分、礼品
			if(Tx == null) Tx = 1;
			var totalNum = 0;
			var totalPri = 0;
			var totalPoi = 0;
			var totalPo_ = 0;
			var totalGif = Array();

			function cal(r){
				var p= 1*r.get('goods_price');
				var n= 1*r.get('goods_num');
				var f= 1*r.get('goods_factor');
				var _c= 1*r.get('_cash');
				var _d= 1*r.get('_discount');
				var _p= 1*r.get('_point');
				var _g= r.get('_gifts');
				totalNum += n;
				totalPri += (p*n-_c)*_d;
				totalPoi += (p*n-_c)*_d*f;
				totalPo_ += _p;
				if(null != _g)
					totalGif =totalGif.concat(_g);

			}
			markStore.each(cal); 
			//将商品列表中的统计结果存入 出售小计数据结构中
			dataRecord.set('goods_num',totalNum);
			dataRecord.set('sum',totalPri);
			dataRecord.set('point',totalPoi);
			dataRecord.set('point_',totalPo_);
			dataRecord.set('gifts',totalGif);

			//下面开始更新 出售小计数据结构中的优惠数据
			var _n ;//暂存优惠中的数量条件
			var _s ;//暂存优惠中的金额条件

			posUpdataDataRecord(dataRecord,0,1,null,true);//初始化小计中的优惠数据
			if(P0 != null){
				//遍历P0
				for (var i = 0;i<P0.length ;i++ ){
					_n = P0[i].get('goods_num');
					_s = P0[i].get('sum');
					if (_n != null && _n < totalNum) continue;//数量条件不空且条件不满足的不复算优惠
					if (_n != null && _s < totalPri) continue;
					if (P0[i].get('loop')!=0 || P0 !=null) 
						posUpdataDataRecord(dataRecord,P0[i].get('cash'),P0[i].get('discount'),P0[i].get('gifts'))
				}
			};
			posShowMaskTotal();//更新商品小计显示
		}

		//计算单个商品的优惠函数(私有)
		function posMarkOneGoodPreCal(dataRecord,P0,P1,P2,Tx){
			if (Tx == null ) Tx = 1;
			var g_id = dataRecord.get('goods_id');
			var g_num =dataRecord.get('goods_num');
			var g_tpri =dataRecord.get('goods_price')*g_num;
			var _n;
			var _s;
			posUpdataDataRecord(dataRecord,0,1,null,true);//初始化商品优惠数据
			if(P1 != null){
				//遍历P1
				for (var i = 0;i<P1.length ;i++ ){
					_n = P1[i].get('goods_num');
					_s = P1[i].get('sum');
					if (P1[i].get('goods_id')!=g_id) continue;
					if (_n != null && _n < g_num) continue;
					if (_n != null && _s <g_tpri) continue;
					if (P1[i].get('loop')!=0 || P0 !=null) 
						posUpdataDataRecord(dataRecord,P1[i].get('cash'),P1[i].get('discount'),P1[i].get('gifts'))
				}
			};
			if(P2 != null){
				//遍历P2
				for (var i = 0;i<P2.length ;i++ ){
					_n = P2[i].get('goods_num');
					_s = P2[i].get('sum');
					if (P2[i].get('goods_id')!=g_id) continue;
					if (_n != null && _n < g_num*1) continue;
					if (_n != null && _s <g_tpri*1) continue;
					if (P2[i].get('loop')!=0 || (P0==null && P1==null) ) 
						posUpdataDataRecord(dataRecord,P2[i].get('cash'),P2[i].get('discount'),P2[i].get('gifts'))
				}
			};

		}


		//用于会员的数据
		var posMemberRecordType = Ext.data.Record.create([
			{name: 'member_id',				mapping: 'member_id'	},//ID
			{name: 'member_consumer_id',	mapping: 'consumer_id'	},//消费者id
			{name: 'member_terminal_id',	mapping: 'terminal_id'	},//终端ID
			{name: 'member_level',			mapping: 'level_id'		},//会员级别
			//{name: 'member_mobile',			mapping: 'mobile'		},//会员手机号
			//{name: 'member_password',		mapping: 'password'		},//密码
			{name: 'member_point',			mapping: 'point'		},//积分
			//{name: 'member_status',			mapping: 'status'		},//状态
			//自己添加的，数据库还没有设计好
			{name: 'member_name',			mapping: 'name'			,defaultValue:null},//名字
			{name: 'member_age',			mapping: 'age'			,defaultValue:null},//年龄
			{name: 'member_sex',			mapping: 'sex'			,defaultValue:null} //性别
		]);
		
		var posMemberMessageReader = new Ext.data.JsonReader({root: "OneMember"}, posMemberRecordType);
		 posMemberMessageStore = new Ext.data.Store({reader:posMemberMessageReader});
		
		
		//下面的代码用于显示出会员基本信息
		// 定义出售商品条码录入域的VType 
		Ext.apply(Ext.form.VTypes, {
			consumerID: function(val, field) {
				return /^\d{11}$/.test(val);
				},
			consumerIDText: '会员ID格式无效'
		});
		// 会员ID输入区域keydown响应函数 
		function keydownInMemberField(thisField,e){
			//回车键响应处理开始
			if (e.ENTER == e.getKey()){
				if((thisField.getValue()!='')&thisField.isValid()){
					thisField.disable();
					Ext.Ajax.request({
						url: 'index.php?controller=Dealing&action=PosGetMemberMsg',
						method:'POST',
						params: { 
								consumer_id: thisField.getValue(), 
								terminal_id: jsCfgData.UserMessage.terminal_id 
							},
						autoAbort:true,
						timeout:3000,
						success: function(response){
							try {
								var ro = Ext.decode(response.responseText);
								if (ro.OneMember == 'failure')
								{
									Ext.Msg.show({
									   title: '注意',
									   msg: ro.message,
									   modal:true,
									   closable:false,
									   multiline:false,
									   buttons: Ext.MessageBox.OK,
									   fn: function(btn, text){	 if (btn == 'ok'){thisField.focus(true);}  },
									   icon: Ext.MessageBox.WARNING
									});
									return;
								}else{
									posMemberMessageStore.loadData(ro);
									posPreferentialStore.loadData(ro);
									Ext.getCmp('pos-form-tabpanel').getActiveTab().getComponent(0).getComponent(0).focus(true);
								}   
							}catch(e){
								Ext.Msg.alert('错误',e);
								   
							}finally {
								thisField.enable();
							}
						},
						failure: function(){
							Ext.Msg.alert('错误','通讯失败！再试一次。');
							thisField.enable();
							thisField.focus(true,500);
						}
					   
					});
				}//end if
				
			}//end if
			//其它键响应处理开始
			
			//if (e.ESC == e.getKey()){
			//}//end if
			
		}//end function keydownInMemberField

		var posMemberMessageTpl = new Ext.XTemplate( //显示会员信息的模板
				'<tpl for=".">',
				'<div class="posMemberMessage">会员信息==&gt ',
				' 姓名:<span class="posMemberMessageFeild"> {member_name} </span>;',
				' 性别:<span class="posMemberMessageFeild">',
					'<tpl if="member_sex==0">',
						' 女 ',
					'</tpl>',
					'<tpl if="member_sex==1">',
						' 男 ',
					'</tpl>',
					'<tpl if="member_sex==null">',
						' ? ',
					'</tpl>',					
				'</span>;',
				' 年龄:<span class="posMemberMessageFeild"> {member_age} </span>岁;',
				' 积分:<span class="posMemberMessageFeild"> {member_point} </span>点;',
				'</div>',
				'</tpl>'
		);

		var posMemberMessageDataView = new Ext.DataView({ //显示会员信息的 DataView
			store: posMemberMessageStore,
			tpl: posMemberMessageTpl,
			autoHeight:true,
			autoLoad:true,
			multiSelect: true,
			overClass:'x-view-over',
			itemSelector:'div.thumb-wrap',
			emptyText: '<div class="posMemberMessage">会员信息==&gt 非会员</div>'
		});
		
		//用于出售的数据
		var goodsRecord = Ext.data.Record.create([
			{name: 'goods_id'				,mapping:'goods_id'			},//编号
			{name: 'goods_barcode'			,mapping:'barcode'			},//条码

			//{name: 'goods_terminal_id'		,mapping:'terminal_id'		},//所属终端

			{name: 'goods_name'				,mapping:'name'				},//名称
			{name: 'goods_price'			,mapping:'price'			},//单价
			{name: 'goods_factor'			,mapping:'factor'			},//积分系数

			//{name: 'goods_status'			,mapping:'status'			},//上架状态
			//{name: 'goods_totalnum'			,mapping:'totalnum'			},//商品总数
			//{name: 'goods_associate'		,mapping:'associate'		},//是否关联库存
			//{name: 'goods_memo'				,mapping:'memo'				},//简介
			//{name: 'goods_goodspic'			,mapping:'goodspic'			},//图片

			{name: 'goods_marketable_num'	,mapping:'marketable_num'	},//可销售数

			//{name: 'goods_rentable_num'		,mapping:'rentable_num'		},//可出租数

			{name: 'goods_num'				,mapping:'num'				,type:'int'		,defaultValue:1	},//购买数量，自动计算或手动给定
			//{name: '_tPrice'											,type:'float'	,convert:function(v,rec){return rec.price}},//金额，由前面的商品属性计算得到

			{name:'_cash'		,type:'float'	,defaultValue:0			},//返现，由优惠处理函数来更新
			{name:'_discount'	,type:'float'	,defaultValue:1			},//折扣，同上
			{name:'_point'		,type:'int'		,defaultValue:0			},//需积分，同上
			{name:'_gifts'		,type:'auto'	,defaultValue:Array()	} //礼品，同上
		]);
		
		var markReader = new Ext.data.JsonReader({root: "OneGoods"}, goodsRecord);
		 markStore = new Ext.data.Store({
				reader:markReader,
				listeners:{
					//如果出售商品中的数据被删除
					remove : function( thisStore,thisRecord,idx ){
						//相应优惠也被删除
						var index;
						do{
							index = posPreferentialStore.find('goods_id',thisRecord.get('goods_id'));
							if (index > -1){posPreferentialStore.remove(posPreferentialStore.getAt(index));}
						}while (index > -1);
						posMarkAllGoodPre();
					}
					,add:function(){posMarkAllGoodPre();}
					,scope	:this
					,delay:50
				}
			});

		//下面的代码用于显示出售的商品列表
		//对单个商品进行删除，增减数量的操作窗口
		var Win;
		function markOptionWin(thisGrid,rowIndex,e){
			
			var nowRecord = thisGrid.getStore().getAt(rowIndex);

			Win = new Ext.Window({
					title:'修改商品购买信息',
					id:'pos-markoption-window',
					autoShow:true,
					defaults:{
						frame:true,
						bodyStyle: 'padding:5px'
					},
					modal:true,
					height:250,
					width:300,
					myStore:thisGrid.getStore(),
					myRow:rowIndex,
					myRecord:nowRecord,
					items:[{
						html:'<h1>商品名称：'+nowRecord.get('goods_name')+' & 可购数量：'+nowRecord.get('goods_marketable_num')+'</h1>'
					},{
						defaults:{border:false},
						items:[{
							html:'<h1>原购买数量：'+nowRecord.get('goods_num')+'</h1>'
						},{
							layout:'form',
							items:[{
								xtype:'numberfield',
								id:'pos-optionwin-goodsnum',
								length:25,
								fieldLabel: '数量修改为',
								minValue:1,
								minText:'数量不能为零',
								maxValue:nowRecord.get('goods_marketable_num'),
								maxText:'数量过多',
								selectOnFocus:true,
								value:nowRecord.get('goods_num')
							}]
						}]
					}],
					buttons:[{
						text:'确认',
						handler:function(btn,e){
							if (Ext.getCmp('pos-optionwin-goodsnum').isValid()){
								btn.disabled=true;
								btn.ownerCt.myRecord.set('goods_num',Ext.getCmp('pos-optionwin-goodsnum').value);
								btn.ownerCt.close();
							}
						}
					},{
						text:'删除',
						handler:function(btn,e){
							btn.disabled=true;
							btn.ownerCt.myStore.remove(btn.ownerCt.myRecord);
							posMarkGrid.getView().refresh(false);
							btn.ownerCt.close();
						}
					},{
						text:'取消',
						handler:function(btn,e){btn.ownerCt.close();}
					}]
			});
			Win.show();
		}
		// 定义出售商品条码录入域的VType //
		Ext.apply(Ext.form.VTypes, {
		  codebar: function(val, field) {
			return /^\d{4}$/.test(val);
		  },
		  codebarText: '条码格式无效'
		});
		// 商品输入区域keydown响应函数 //
		function keydownInMarkField(thisField,e){
			//回车键响应处理开始
			if (e.ENTER == e.getKey()){
				
				//要做一些准备工作再通讯请求数据
				var needRequest = false;

				if((thisField.getValue()!='')&thisField.isValid()){
					var msIndex = markStore.find('goods_barcode',thisField.getValue());
					if (msIndex != -1)//如果在 出售 数据集 中存在
					{
						posMarkGrid.getSelectionModel().selectRow(msIndex);
						msIndex = markStore.getAt(msIndex);
						msIndex.set('goods_num',msIndex.get('goods_num')+1);
						
					}else{
						needRequest = true;
					}
				}
				thisField.focus(true);
				if (needRequest){
					thisField.disable();//如果先disable，isValid不做判断 kao ,花了我两三个小时，才搞清楚
					Ext.Ajax.request({
						url: 'index.php?controller=Dealing&action=PosGetGoodsMsg',
						method:'POST',
						params: { 
							goods_barcode :	thisField.getValue()																		,//
							terminal_id   :	jsCfgData.UserMessage.terminal_id															,//
							member_level  :	posMemberMessageStore.getAt(0)?posMemberMessageStore.getAt(0).get('member_level'):''		,//	
							consumer_id   :	posMemberMessageStore.getAt(0)?posMemberMessageStore.getAt(0).get('member_consumer_id'):''   //
							},
						autoAbort:true,
						timeout:3000,
						success: function(response){
							try {
								var ro = Ext.decode(response.responseText);
								if (ro.OneGoods == 'failure')
								{
									Ext.Msg.show({
									   title: '注意',
									   msg: ro.message,
									   modal:true,
									   closable:false,
									   multiline:false,
									   buttons: Ext.MessageBox.OK,
									   fn: function(btn, text){	 if (btn == 'ok'){thisField.focus(true);}  },
									   icon: Ext.MessageBox.WARNING
									});
									return;
								}else{
									markStore.loadData(ro,true);
									posPreferentialStore.loadData(ro,true);
									var scro = posMarkGrid.getView().scroller.dom;
									scro.scrollTop=scro.scrollHeight;
									posMarkGrid.getSelectionModel().selectLastRow();
									thisField.focus(true,500);
								}   
							}catch(e){
								Ext.Msg.alert('错误',e);
								   
							}finally {
								thisField.enable();
							}
						},
						failure: function(){
							Ext.Msg.alert('错误','通讯失败！再试一次。');
							thisField.enable();
							thisField.focus(true,500);
						}
					   
					});
				}//end if
				
			}//end if
			//其它键响应处理开始
			
			//if (e.ESC == e.getKey()){
			//}end if
			//
		}//end function keydownInMarkField

		//renderer function 1.序号
		//function markRowNum(val, cellmeta, record, rowIndex){
		//	return rowIndex +1;
		//}
		//renderer function 2.优惠显示
		function markPreferentialsShow(val, cellmeta, record, rowIndex,store){
			var out = '';
			var thisGifts = record.get('_gifts');
			for (var i=0;i++;i<thisGifts.length){
				out = '礼品id:'+thisGifts[i][0]+'X'+thisGifts[i][1]+'个;';
			};
			out = 	(record.get('_cash')==0?'':'返现:'+record.get('_cash')+'元;')
				+	(record.get('_discount')==1?'':'折扣:'+record.get('_discount')+';');
			return out==''?'无':out;
		}
		//renderer function 3.该商品金额显示
		function markSumRowMoney(val, cellmeta, record, rowIndex, colIndex, store){
			return "￥"+(record.get('_discount')*record.get('goods_num')*val-record.get('_cash')).toFixed(2);
		}
		//renderer function 4.该商品积分
		function markPointShow(val, cellmeta, record, rowIndex, colIndex, store){
			return "JF:"+(record.get('goods_num')*record.get('goods_price')*val).toFixed(2);
		}

		var posMarkGrid = new Ext.grid.GridPanel({
			id:'posMarkGrid',
			store: markStore,
			columns: [
				new Ext.grid.RowNumberer(),
				//{header: "序号",		width: 30, sortable: false, renderer:markRowNum},
				{header: "商品名称"	,width: 90	,sortable: false	,dataIndex:'goods_name',id:'posMarkGridGoodsName'},
				{header: "数量"		,width: 30	,sortable: false	,dataIndex:'goods_num'},
				{header: "单价"		,width: 60	,sortable: false	,dataIndex:'goods_price',renderer:function(val){return "￥"+(val*1).toFixed(2);}},
				{header: "积分"		,width: 80	,sortable: false	,dataIndex:'goods_factor',renderer:markPointShow},
				{header: "系数"		,width: 30	,sortable: false	,dataIndex:'goods_factor'},
				{header: "优惠"		,width: 120	,sortable: false	,dataIndex:'goods_price',renderer:markPreferentialsShow},
				{header: "金额"		,width: 80	,sortable: false	,dataIndex:'goods_price',renderer:markSumRowMoney}
			],
			autoExpandColumn: 'posMarkGridGoodsName',
			stripeRows:true,
			sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
			listeners:{rowdblclick:markOptionWin}
		});//end posMarkGrid

	 // Here is FormPanel border disign
		var posNorth = {
			region:"north",
			height:65,
			items:[{
					//一、会员ID输入区域（ 分3列）
					layout:'column',
					width:600,
					items:
						[{//1.会员id输入域
							columnWidth:.75,
							layout:'form',
							labelWidth:70,
							items:[{
								xtype:'textfield',
								id:'pos-form-consumer-field',
								disabled:true,
								anchor:'90%',//输入框宽度自动调整至90%
								fieldLabel: '会员ID输入',
								labelSeparator: ':',								
								name: 'consumer_id',
								vtype: 'consumerID',
								listeners:{specialkey:keydownInMemberField}
							}]
						},{//2.非会员勾选
							columnWidth:.25,
							layout:'form',
							labelWidth:45,
							items:[{
								style:'margin-top:5px',
								xtype:'checkbox',
								checked:true,
								id:'pos-form-member-check',
								fieldLabel: '非会员',
								name: 'is_not_member',
								listeners:{check:inputEnableCtr}
							}]
						},{//3.暂时空
						}]
				
			},//二、会员基本信息显示区域
				posMemberMessageDataView
			]
		};
		var posEast = {
			region:'east',
			floatable: false,
			//margins: '5 0 0 0',
			//cmargins: '5 5 0 0',
			width: 200,
			//height:200,
			autoScroll:true,
			minSize: 100,
			maxSize: 250,
			title:'优惠列表',
			items:[{
				width: 170,
				items:[posPreferentialMessageDataView]
			},{//用于显示优惠说明
				width: 170,
				html: '<p>点击优惠显示说明</p>'
				
			}]
		};
		var posCenter = {
			collapsible: false,
			region:'center',
			margins: '5 0 0 0',
			layout:'fit',
			//三、交易和优惠列表区域
			items:[{
				xtype:'tabpanel',
				id:'pos-form-tabpanel',
				defaults:{frame:true},
				//height:300,
				activeTab: 0,
				listeners: {
					bodyresize:function( p,w,h ){
						//posMarkGrid.setHeight(h-70);
						posMarkGrid.setSize(w-15,h-200);
						
					}
				},
				
				items:[{
					title:'出售',
					
					items:[{
						layout:'form',
						defaultType: 'textfield',
						items:[{
							anchor:'90%',
							fieldLabel:'出售商品条码',
							vtype: 'codebar',
							listeners:{specialkey:keydownInMarkField}
						},
							posMarkGrid
						]
					},{
						layout:'fit',
						id :'pos-mark-total-view',
						height:20,
						listeners:{render:{fn:posShowMaskTotal,scope:this,delay:50}},
						html:'<p>出售小计：</p>'
					}]
				},{
					
					title:"出租",
					layout:'form',
					defaults: {width: 230},
					defaultType: 'textfield',
					items:[{
						fieldLabel:'出租商品条码',
						name:'goods_code3'
					},{
						fieldLabel:'商品',
						name:'goods_code4'
					}]
				},{
					title:"归还",
					layout:'form',
					defaults: {width: 230},
					defaultType: 'textfield',
					items:[{
						fieldLabel:'归还商品条码',
						name:'goods_code3'
					},{
						fieldLabel:'商品',
						name:'goods_code4'
					}]
				}]
			}]
		};
		var posSouth = {
			region: 'south',
			height: 75,
			minSize: 75,
			maxSize: 250,
			cmargins: '5 0 0 0',
			html: '<p>Footer content</p>'
		};
	//中间变量结束
		return new Ext.Panel({
	//主页面开始
			layout:'fit',
			id: 'pos-form',
			bodyStyle: 'padding:5px',
			items:[{
				layout:'border',
				defaults: {
					frame:true,
					border:false,
					animFloat: false,
					autoHide: false
				},
				items:[posNorth,posCenter,posEast,posSouth] //POS页显示，分成四大区域，宽度为600
			}]

	//主页面结束
		});
//主设计结束
     },   //end createPanel:funtion()
    //重装控件初始化函数,在该函数中完成面板中内容的初始化  
    initComponent:function() {  
        dealing_pos.superclass.initComponent.call(this);  
        this.fp = this.createPanel();  
        this.add(this.fp); 
    }
	
});